View Javadoc
1 /* 2 * Angkor Web Framework 3 * 4 * Distributable under LGPL license. 5 * See terms of license at gnu.org. 6 */ 7 8 package com.tirsen.angkor; 9 10 import com.tirsen.angkor.process.Pipeline; 11 12 import javax.servlet.ServletConfig; 13 import javax.servlet.ServletException; 14 import javax.servlet.http.HttpServlet; 15 import javax.servlet.http.HttpServletRequest; 16 import javax.servlet.http.HttpServletResponse; 17 import java.io.IOException; 18 19 /*** 20 * Fetches a named component based either on configuration in a init parameter or on the last 21 * part of the request uri, the named component is fetched from the application instantiated by the 22 * ApplicationFilter which must be mapped to all requests to this servlet. 23 * 24 * <!-- $Id: ComponentServlet.java,v 1.6 2002/10/13 13:37:26 tirsen Exp $ --> 25 * 26 * @author $Author: tirsen $ 27 * @version $Revision: 1.6 $ 28 */ 29 public class ComponentServlet extends HttpServlet 30 { 31 private String componentName; 32 33 public void init(ServletConfig config) throws ServletException 34 { 35 super.init(config); 36 componentName = config.getInitParameter("componentName"); 37 } 38 39 protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException 40 { 41 if (componentName == null) 42 { 43 String requestURI = request.getRequestURI(); 44 componentName = requestURI.substring(requestURI.lastIndexOf("/") + 1); 45 } 46 47 RenderContext ctx = new RenderContext(request, response); 48 49 Application application = ctx.getApplication(); 50 51 ViewFactory factory = application.getComponent(componentName); 52 Pipeline pipeline = application.createRenderPipeline(factory); 53 try 54 { 55 pipeline.execute(ctx); 56 } 57 catch (Exception e) 58 { 59 throw new ServletException(e); 60 } 61 if (application.getError() != null) throw new ServletException(application.getError()); 62 } 63 }

This page was automatically generated by Maven